#include "Character/Character.h"
#include "Community/ChannelManager.h"
#include <netlib/net/inetaddress.h>

Character::Character() : m_slot( INVALID_SLOT )
{
}

Character::~Character()
{
}

void Character::initialize()
{
	m_playingChannel = NULL;
	ZeroMemory( m_userID, CHARACTER_ID_LENGTH + 1 );
	m_ready = false;
	m_isChannaleMaster = false;
	m_isStartedGame = false;
}

void Character::onClose()
{
	ChannelManager::getInstance()->leave( this );
}

void Character::onHackingUser()
{
}

void Character::onConnect()
{
}


Channel *Character::getPlayingChannel()
{
	return ( m_playingChannel );
}

GameRoom *Character::getPlayingGameRoom()
{
	if ( m_playingChannel == ChannelManager::getInstance()->getLobby() ) return ( NULL );
	return ( ( GameRoom *)m_playingChannel );
}

void Character::setPlayingChannel( Channel *channel )
{
	m_playingChannel = channel;
}

bool Character::send( netlib::packet::Packet *packet , bool encrypt )
{
	if ( !m_session ) return ( false );
	return ( m_session->send( packet , encrypt ) );
}

char *Character::getUserID()
{
	return ( m_userID );
}

void Character::setUserID( char *userID )
{
	ZeroMemory( m_userID, CHARACTER_ID_LENGTH + 1 );
	strncpy_s( m_userID, userID , CHARACTER_ID_LENGTH );
}

void Character::setReady( bool ready )
{
	m_ready = ready;
}

bool Character::isReady()
{
	return ( m_ready );
}

void Character::setChannelMaster( bool isMaster )
{
	m_isChannaleMaster = isMaster;
}

bool Character::isChannelMaster()
{
	return ( m_isChannaleMaster );
}

BYTE Character::getSlot()
{
	return ( m_slot );
}

void Character::setSlot( BYTE slot  )
{
	m_slot = slot;
}

bool Character::isStartedGame()
{
	return ( m_isStartedGame );
}

void Character::setStartedGame( bool isStartedGame )
{
	m_isStartedGame = isStartedGame;
}